package com.simple.car.loader.server.tools;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

public class ThreadPool {

    private static ThreadPool threadPool = new ThreadPool();

    private ExecutorService executorService;

    private ThreadPool(){
        executorService = Executors.newCachedThreadPool();
    }

    public static ThreadPool getInstance(){
        if (threadPool == null){
            threadPool = new ThreadPool();
        }
        return threadPool;
    }

    public void addTask(Runnable runnable){
        executorService.submit(runnable);
    }

    public void release(){
        executorService.shutdownNow();
    }
}
